<?php
require_once ROOT_PATH . '/lib/models/hrfunct/EmpInfo.php';
require_once ROOT_PATH . '/lib/models/recruitment/JobVacancy.php';
require_once ROOT_PATH . '/lib/models/recruitment/JobApplicationEvent.php';

$application = $records['application'];
$jobVacancy = JobVacancy::getJobVacancy($application->getVacancyId());
$manager = $jobVacancy->getManagerId(); 
//$events = $application->getEvents();
//$latestEvent = $application->getLatestEvent();



$interviewers = explode(",", $application->getInterviewers(JobApplicationEvent::EVENT_SCHEDULE_SECOND_INTERVIEW));
$event = $application->getEventOfScheduledInterview(JobApplicationEvent::EVENT_SCHEDULE_SECOND_INTERVIEW);


//$interviewers = $application->getInterviewers(2);
if(!in_array($manager,$interviewers)){
	$interviewers[]=$manager;
}

$baseURL = "{$_SERVER['PHP_SELF']}?recruitcode={$_GET['recruitcode']}";
$editEventURL = $baseURL . '&action=SaveInterviewAssessment';
define('ROOT_PATH3', dirname(__FILE__));

$txtResult = CommonFunctions::escapeHtml(file_get_contents(ROOT_PATH3.'/applicant/textareafields/result1.htm'));


$statusList = array(
    JobApplication::STATUS_SUBMITTED => $lang_Recruit_JobApplicationStatus_Submitted,
    JobApplication::STATUS_FIRST_INTERVIEW_SCHEDULED => $lang_Recruit_JobApplicationStatus_FirstInterview,
    JobApplication::STATUS_SECOND_INTERVIEW_SCHEDULED => $lang_Recruit_JobApplicationStatus_SecondInterview,
    JobApplication::STATUS_JOB_OFFERED => $lang_Recruit_JobApplicationStatus_JobOffered,
    JobApplication::STATUS_OFFER_DECLINED => $lang_Recruit_JobApplicationStatus_OfferDeclined,
    JobApplication::STATUS_PENDING_APPROVAL => $lang_Recruit_JobApplicationStatus_PendingApproval,    
    JobApplication::STATUS_REJECTED => $lang_Recruit_JobApplicationStatus_Rejected,
    JobApplication::STATUS_ACCEPTED => $lang_Recruit_JobApplicationStatus_Accepted,
    JobApplication::STATUS_UN_ACCEPTED => $lang_Recruit_JobApplicationStatus_Unaccepted,
    JobApplication::STATUS_RESETED => $lang_Recruit_JobApplicationStatus_Reseted,
    JobApplication::STATUS_APPROVED => $lang_Recruit_JobApplicationStatus_Approved,
    JobApplication::STATUS_HIRED => $lang_Recruit_JobApplicationStatus_Hired
    );

$eventStatusList = array(
    JobApplicationEvent::STATUS_INTERVIEW_SCHEDULED => $lang_Recruit_JobApplicationHistory_StatusInterviewScheduled,
    JobApplicationEvent::STATUS_INTERVIEW_FINISHED => $lang_Recruit_JobApplicationHistory_StatusFinished,
);

$eventTitles = array(
    JobApplicationEvent::EVENT_REJECT => $lang_Recruit_JobApplicationHistory_Rejected,
    JobApplicationEvent::EVENT_SCHEDULE_FIRST_INTERVIEW => $lang_Recruit_JobApplicationHistory_FirstInterview,
    JobApplicationEvent::EVENT_SCHEDULE_SECOND_INTERVIEW => $lang_Recruit_JobApplicationHistory_SecondInterview,
    JobApplicationEvent::EVENT_OFFER_JOB => $lang_Recruit_JobApplicationHistory_OfferedJob,
    JobApplicationEvent::EVENT_MARK_OFFER_DECLINED => $lang_Recruit_JobApplicationHistory_OfferMarkedAsDeclined,
    JobApplicationEvent::EVENT_SEEK_APPROVAL => $lang_Recruit_JobApplicationHistory_SeekApproval,
    JobApplicationEvent::EVENT_APPROVE => $lang_Recruit_JobApplicationHistory_Approved,
    JobApplicationEvent::EVENT_REJECT => $lang_Recruit_JobApplicationHistory_Rejected
);

$picDir = "../../themes/{$styleSheet}/pictures/";
$iconDir = "../../themes/{$styleSheet}/icons/";

$backImg = $picDir . 'btn_back.gif';
$backImgPressed = $picDir . 'btn_back_02.gif';

?>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="../../scripts/archive.js"></script>
<script type="text/javascript" src="../../scripts/octopus.js"></script>
<?php include ROOT_PATH."/lib/common/calendar.php"; ?>
<script src="../../scripts/time.js"></script>
<script>
	var dateTimeFormat = YAHOO.OrangeHRM.calendar.format + " " + YAHOO.OrangeHRM.time.format;	
    function goBack() {
        location.href = "<?php echo "{$baseURL}&action=List"; ?>";
    }

    function addEditMode(btn) {
        if (!('editMode' in btn)) {
            btn.editMode = false;
        }
    }

    function edit(btn, formId) {

        addEditMode(btn);
        form = $(formId);

        if(btn.editMode) {
            form.submit();
        } else {
            btn.editMode = true;
            form.txtNotes.disabled = false;
            if ('cmbStatus' in form) {
                form.cmbStatus.disabled = false;
            }
            if ('txtSalary' in form) {
                form.txtSalary.disabled = false;
            }
            if ('txtAvailabletime' in form) {
                form.txtAvailabletime.disabled = false;
            }
            if ('txtSecondInterview' in form) {
                form.txtSecondInterview.disabled = false;
            }
            if ('txtSuitable' in form) {
                form.txtSuitable.disabled = false;
            }
            if ('txtRecommendation' in form) {
                form.txtRecommendation.disabled = false;
            }
            btn.src= '<?php echo $picDir;?>btn_save.gif';
        }
    }

    function mout(btn) {
        addEditMode(btn);
        if(btn.editMode) {
            btn.src= '<?php echo $picDir;?>btn_save.gif';
        } else {
            btn.src= '<?php echo $picDir;?>btn_edit.gif';
        }
    }

    function mover(btn) {
        addEditMode(btn);
        if(btn.editMode) {
            btn.src= '<?php echo $picDir;?>btn_save_02.gif';
        } else {
            btn.src='<?php echo $picDir;?>btn_edit_02.gif';
        }
    }
YAHOO.OrangeHRM.container.init();
</script>

    <link href="../../themes/<?php echo $styleSheet;?>/css/style.css" rel="stylesheet" type="text/css">
    <style type="text/css">@import url("../../themes/<?php echo $styleSheet;?>/css/style.css"); </style>

    <style type="text/css">
    <!--

    label, .txtName,.txtValue,.txtBox, .eventTitle {
        display: block;  /* block float the labels to left column, set a width */
        float: left;
        margin: 3px 0px 2px 0px; /* set top margin same as form input - textarea etc. elements */
    }

    .txtName, .eventTitle {
        text-align: left;
        width: 100px;
        padding-left: 10px;
    }

    .txtValue {
        width: auto;
    }

    .txtName, .txtBox, .eventTitle {
        margin-left: 10x;
        padding-left: 4px;
        padding-right: 4px;
    }

    .col2 {
        text-align: right;
        padding-right: 10px;
    }

    label {
        text-align: left;
        width: 100px;
        padding-left: 4px;
        padding-right: 4px;
    }

    textarea {
        width: 300px;
        height: 50px;
        padding-right: 0px;
        color: #444444;
    }

    .eventTitle {
        width: 95%;
        background-color: #EEEEEE;
        border-style: solid;
        border-width: 0px 0px 1px 0px;
        border-color: #888888;
    }

    .txtBox {
        width: 100px;
    }

    br {
        clear: left;
    }

    .roundbox {
        margin-top: 10px;
        margin-left: 15px;
        margin-right: auto;
        width: 600px;
    }

    body {
    	margin-top: 10px;
        margin-left: auto;
        margin-right: auto;
        width: 780px;
    }

    .roundbox_content {
        padding:5px;
    }

	.hidden {
		display: none;
	}

	.display-block {
		display: block;
	}
    .eventDate {
        font-style: italic;
    }
    -->
</style>
<script type="text/javascript" src="../../scripts/tiny_mce/tiny_mce.js"></script>
	<script type="text/javascript">
	tinyMCE.init({
		mode : "textareas",
		theme : "simple",
		editor_selector : "mceSimple",
		width : "450",
		height:"200"
	});
	</script>
</head>
<body>
    <?php
        $applicantName = CommonFunctions::escapeHtml($application->getFirstName() . ' ' . $application->getLastName());
        $jobTitleName = CommonFunctions::escapeHtml($application->getJobTitleName());
        $heading = $applicantName . ' - ' . $lang_Recruit_JobApplicationHistory_ApplicationForThePositionOf .
            ' ' . $jobTitleName . ' <br />' . "Interview Assessment";
    ?>
	<h2 class="moduleTitle"><?php echo $heading; ?></h2>
  	<div id="navigation" style="margin:0;">
  		<img title="<?php echo $lang_Common_Back;?>" onMouseOut="this.src='<?php echo $backImg; ?>';"
  			 onMouseOver="this.src='<?php echo $backImgPressed;?>';" src="<?php echo $backImg;?>"
  			 onClick="goBack();">
	</div>
    <?php $message =  isset($_GET['message']) ? $_GET['message'] : null;
    	if (isset($message)) {
			$col_def = CommonFunctions::getCssClassForMessage($message);
			$message = "lang_Common_" . $message;
	?>
	<div class="message">
		<font class="<?php echo $col_def?>" size="-1" face="Verdana, Arial, Helvetica, sans-serif">
			<?php echo (isset($$message)) ? $$message: ""; ?>
		</font>
	</div>
	<?php }	?>
  <div class="roundbox">
        <?php
            $authManager = new RecruitmentAuthManager();
            $auth = new authorize($_SESSION['empID'], $_SESSION['isAdmin']);
            $role = $authManager->getRoleForApplication($auth, $application);
            $allowEdit =true;
			$allowStatusChange = true;
                    $showStatus = true;
                    
        ?>
        <div class="eventTitle"><?php echo "Interview assessment"; ?></div></br>
        <form id="<?php echo "frmEvent"; ?>" name="<?php echo "frmEvent"; ?>"
            method="post" action="<?php echo $editEventURL;?>">
        <input type="hidden" id="txId" name="txtId" value="<?php echo $application->getId();?>"/>
        <input type="hidden" id="eventType" name="eventType" value="2"/>           

            <div class="txtName"><?php echo $lang_Recruit_JobApplicationHistory_Interviewer; ?></div>
          <div class="txtValue">
            <select id="txtOwner" name="txtOwner" tabindex="1" >
                <?php                
 				for($i = 0; $i <count($interviewers);$i++){                
                	$interviewer = $interviewers[$i];
                    $selected2 = ($interviewer == $_SESSION['empID']) ? 'selected' : '';
	                echo "<option " . $selected2 . " value=". $interviewer . ">" . EmpInfo::getFullName($interviewer) . "</option>";
                }
                ?>
       		 </select>
            </div>
            
            <?php if ($allowStatusChange && $manager == $_SESSION['empID']) { ?>
            <br/>
            <div class="txtName"><?php echo $lang_Recruit_JobApplicationHistory_Status; ?></div>
                <select name="cmbStatus" disabled="true" >
                    <?php
                    foreach ($eventStatusList as $status=>$statusName) {
                        $selected = ($status == $event->getStatus()) ? 'selected' : '';
                        echo "<option $selected value=". $status . ">" . $statusName . "</option>";
                    }
                    ?>
                </select>
                 
            <?php } ?>
            <br />
			<label for="txtSalary"><?php echo "Expected salary"; ?></label>
            <input type="text" name="txtSalary" id="txtSalary" disabled="disabled" value="<?php //echo $event->getSalary();  ?>"/><br/>
            <label for="txtAvailabletime"><?php echo "Available time"; ?></label>
            <input type="text" id="txtAvailabletime" name="txtAvailabletime" value="<?php //echo date('Y-m-d',strtotime($availableTime)); ?>" disabled="disabled" />
        	<input type="button" id="btnToDate" name="btnToDate" value="  " class="calendarBtn"/><br/>
            <label for="txtSecondInterview"><?php echo "Suggest offer job"; ?></label>
            <select name="txtSecondInterview" id="txtSecondInterview" disabled="disabled" />
            		<option value="1" >Yes</option>
            		<option value="0" selected>No</option>
 
            </select>
             <br/>       
           
            <label for="txtSuitable"><?php echo "Suitable for"; ?></label>
            <input type="text" name="txtSuitable" id="txtSuitable" disabled="disabled" value="" /><br/>
             <label for="txtRecommendation"><?php echo "Recommendation"; ?></label>
            <textarea name="txtRecommendation" id="txtRecommendation" disabled="disabled" cols="50" rows="3" /></textarea><br/>
            <br/>
            
            <label for="txtNotes"><?php echo "Assessment"; ?></label>
            <textarea name="txtNotes" disabled="true" class="mceSimple"><?php echo $txtResult; ?></textarea>
            <?php if ($allowEdit) { ?>
            <img onClick="edit(this, '<?php echo "frmEvent"; ?>');" name="editBtn"
                onMouseOut="mout(this);" onMouseOver="mover(this);"
                src="<?php echo $picDir;?>/btn_edit.gif">
            <?php } ?>
            <br/><br/>

        </form>

        <?php
            /* }
            if ($eventCount == 0) {
                echo $lang_Recruit_JobApplicationHistory_NoEvents;
            }
	*/
        ?>
  </div>
  <script type="text/javascript">
        <!--
        	if (document.getElementById && document.createElement) {
   	 			initOctopus();
			}
        -->
  </script>
<div id="cal1Container" style="position:absolute;" ></div>
</body>
</html>
